<?php

include 'format.php';

FormatHeader();
function Mno_user(&$username){
	echo '<h1> Username does not exist </h1>';
	echo_log();
	$username=false;
	return false;
}
$WPOJ_Is_Logged = 0;
if ($_COOKIE["user"] && $_COOKIE["password"]){
	mysql_connect("localhost", "root", "apache") or die(mysql_error());
	mysql_select_db("jobs") or die(mysql_error());
	$username=true;
	//echo $_COOKIE["user"].$_COOKIE["password"];
	//echo "SELECT * FROM users where user = '".$_COOKIE["user"]."'";
	$result = mysql_query("SELECT * FROM users where user = '".$_COOKIE["user"]."'") or die(mysql_error()); 
	$row = mysql_fetch_array( $result ) or Mno_user($username);
	if ($username == true){
		if ($_COOKIE["password"]){
			$encryptpass = $_COOKIE["password"];
			if ($encryptpass == $row['password']){
				echo '<a href="/logout.php">Log Out</a><br>';
				echo $row['user'].'<br><hr>';
				$WPOJ_Is_Logged = 1;
				$WPOJ_User = $row['user'];
				$WPOJ_Rank = $row['rights'];
				if ($row['rights'] > 0){
					if ($row['rights'] == 2){
						// pun ce apare la admini
						# forum admin
						echo '<a href="/reeval.php">reevaluate submissions</a><br>';
						echo '<a href="/forum/adm">forum admin</a><br>';
						echo '<a href="/addcontest.php">add contest</a><br><hr>';
					}
					echo '<a href="/addproblem.php">add problem</a><br>';
					echo '<a href="/uploadfiles.php">upload files</a><br>';
					echo '<a href="/myproblemlist.php">problem list</a><br><hr>';					
					// pun ce apare la admini + helperi
				}
				echo '<a href="/myaccount.php">my account</a><br>';
				// pun ce apare la toti
				echo '<br>';
			}
			else
				echo_unreg();
		}
		else
			echo_unreg();
	}
	else
		echo_unreg();
}
else
	echo_unreg();
echo '
	<a href="/status.php">status</a><br>
	<a href="/submit.php">submit</a><br>
	<a href="/problems.php">problems</a><br><br>
	<a href="/">news</a><br>
	<a href="/contests.php">contests</a><br>
	<a href="/ranks.php">ranks</a><br><br>
	<a href="/forum">forum</a><br>
	<a href="/help.php">help</a><br><hr></div><div class="time">
Server time:
</div>
<div class="time">';
echo date("Y-m-d");
echo '<br><b>';
echo date("H : m : s");
echo '</b>
</div>
</td><td class="content" width="99%">
<p align="justify">';


	$task = $_GET['task'];
	if (!$task){
		echo 'Please specify a problem';
	}
 mysql_connect("localhost", "root", "apache") or die(mysql_error());
 mysql_select_db("jobs") or die(mysql_error());
	mysql_query("update problem set text = '
<p align=\"justify\">

<p>Your task is to read two numbers a and b (0 < a, b <2100000000) and to output their sum.

<h3>Input</h3>
<p>Input contains two lines, on the first line the number a and on the second line the number b. 

<h3>Output</h3>
<p>Output the sum of the two numbers.

<h3>Example</h3>

<pre>
<b>Input:</b>
20
30

<b>Output:</b>
50
</pre>

' where name = 'adun'") or die (mysql_error());
	
	
 $result = mysql_query("select * from problem where name = '".$task."'") or die(mysql_error());  
 $i = 0;
 if ( $row = mysql_fetch_array( $result )){
	echo'
	<body  bgcolor=#FFFFFF style = \'font-size : 9pt;\' text=#FFFFFF link=#336699 vlink=#336699 alink=#336699><div align="center">
		<TABLE BORDER="5"    WIDTH="100%"   CELLPADDING="4" CELLSPACING="3">
	   <TR ALIGN="CENTER">';
            echo '<TH> Input file / Output file</TH> <TD> '.$row['name'].'.in / '.$row['name'];'.out </TD>';
            echo '<TH> Source Contest</TH> <TD> '.$row['contest'].' </TD></TR>';
            echo '<TR ALIGN="CENTER"><TH> Author </TH><TD>'.$row['author'].'</TD><TH> Added by </TH><TD>'.$row['adder'].'</TD></TR>';
            echo '<TR ALIGN="CENTER"><TH> Time Limit </TH><TD>'.$row['time'].' second(s)</TD><TH> Memory Limit: Heap / Stack </TH><TD>'.$row['memHeap'].' / '.$row['memStack'].' kbytes</TD></TR>';
           // echo 'TR'
           
        echo '</TABLE></div></body>';
        
        
        echo '<div class="prob">

<h2>WPOJ Problem Set </h2>

<h1>'.$row['longname'].'</h1>
<h2>Problem code: '.$row['name'].'</h2>'; echo $row['text'];
 }
 else
 	echo '<h1> Problem does not exist </h1>';
 echo'
 </body>';
FormatFooter();
?>
